package bomberman.runable;

import java.util.List;

import bomberman.model.Flame;
import bomberman.util.Constants;

/**
 * 火焰变化线程，控制火焰变弱
 * @author EX-FUHUICHAO001
 * 2016年9月22日17:49:04
 */
public class MyRunableFlameChange implements Runnable {

	private List<Flame> flames;
	
	public MyRunableFlameChange(List<Flame> flames){
		this.flames = flames;
	}
	
	public void run() {
		try {
			// 因为是统一变化的，所以只取第一个做判断
			Flame flame = flames.get(0);
			
			// 若火焰未移除，则变化火焰变细（switch...case和if...else性能比较）
			while(!flame.isRemove()){
				Thread.sleep(Constants.FLAME_CHANGE_SLEEP_TIME);
				for(Flame f : flames){
					if(f.getSize() == Constants.FLAME_SIZE_BIG){
						f.setSize(Constants.FLAME_SIZE_MIDDLE);
					}
					else if(f.getSize() == Constants.FLAME_SIZE_MIDDLE){
						f.setSize(Constants.FLAME_SIZE_SMALL);
					}
					else if(f.getSize() == Constants.FLAME_SIZE_SMALL){
						f.setSize(Constants.FLAME_SIZE_SSMALL);
					}
				}
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	
	public List<Flame> getFlames() {
		return flames;
	}

	public void setFlames(List<Flame> flames) {
		this.flames = flames;
	}


	
}
